﻿namespace Visitor
{
    internal class Directory : Entry
    {
        private readonly string name;
        private readonly List<Entry> directory = new List<Entry>();

        public Directory(string name)
        {
            this.name = name;
        }

        public override string GetName()
        {
            return name;
        }

        public override int GetSize()
        {
            return directory.Select(d => d.GetSize()).Sum();
        }

        public Entry Add(Entry entry)
        {
            directory.Add(entry);
            return this;
        }

        public IEnumerator<Entry> GetEnumerator() 
        {
            return directory.GetEnumerator();
        }

        public override void Accept(VisitorAbstract visitor)
        {
            visitor.Visit(this);
        }
    }
}
